package com.byit.controller;

import com.alibaba.fastjson.JSONObject;
import com.byit.builder.MapBuilder;
import com.byit.config.MinioConfig;
import com.byit.domain.AppCertificate;
import com.byit.domain.SysAppVersion;
import com.byit.enums.PromptInfo;
import com.byit.jwt.ann.JwtUser;
import com.byit.jwt.domain.JwtSession;
import com.byit.msg.MessageResult;
import com.byit.service.ISysAppVersionService;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @ClassName AppVersionController
 * @Description App版本管理
 * @Author lxp
 * @Date 2019-01-18 10:26
 **/
@RestController
@RequestMapping("/app/appVersion")
public class AppVersionController {


    private Logger logger = LoggerFactory.getLogger(this.getClass());


    @Autowired
    private ISysAppVersionService appVersionService;


    /**
     * 获取app版本信息
     *
     * @param session
     * @return
     */
    @GetMapping("/getAppVersion")
    public Object list(@JwtUser JwtSession session,
                       @RequestParam("type") int type) {
        Long userId = session.userId();

        SysAppVersion appVersion = new SysAppVersion();
        appVersion.setType(type);
        // Long userId = SessionHelper.getUserId(session);
        try {

            // 加密用户密码
            appVersion.setOperationId(userId);

            Map<String, Object> params = MapBuilder.newMap(3)
                    .setParam("type", type)
                    .ok();

            List<JSONObject> appCertificateList = appVersionService.selectSysAppVersionList(params);
            JSONObject jsonObject = null;
            if (appCertificateList.size() >= 1) {
                jsonObject = appCertificateList.get(0);
            }
            return MessageResult.warpper(PromptInfo.SYS_SECCUSS, jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
            return MessageResult.error(e);
        }
    }

}
